using System;
using Nsb.Classes;

namespace Yoshi.Fb
{
    // Facebook graph api extensions


    public partial class FbDataStore
    {
        public void RetrieveFriends(FnDelegate1 fn)
        {
            if (!Script.IsValue(User))
                return;
            GetCache(User.id, "friends",
                delegate(object fbo)
                    {
                        if (Script.IsValue(fn))
                            fn(fbo);
                        Inform.Log("RetrieveFriends - Friend count = {0}", ((FbResult) fbo).data.Length);
                    }
                );
        }

        public void RetrievePhotos(string albumName, FnDelegate1 fn)
        {
            if (!Script.IsValue(User))
                return;
            GetCache(User.id, "albums",
                delegate(object fbo)
                    {
                        FbAlbum[] albums = (FbAlbum[]) ((FbResult) fbo).data;
                        string albumId = "";
                        if (Script.IsValue(albums))
                        {
                            foreach (FbAlbum a in albums)
                            {
                                if (a.name != albumName) continue;
                                albumId = a.id;
                                break;
                            }
                        }
                        GetCache(albumId, "photos",
                            delegate(object fbo2)
                                {
                                    FbPhoto[] photos = (FbPhoto[]) ((FbResult) fbo2).data;
                                    if (Script.IsValue(fn))
                                        fn(photos);
                                }
                            );
                    }
                );
        }

    }
}